-2 -1 0 1The first number printed is "-2" because
COUNT was started
out at -2 and -2 < 2 is true.
Then COUNT is changed to -1 and LOOP sends execution back
to the DO WHILE.
Since -1 < 2 is true, "-1" is printed.
And so on.
So far you have seen two tests: less than or equal and less than. QBasic can do more than that. Here is a complete list:
| Symbol | Example | Meaning |
|---|---|---|
| = | A = B | is A equal to B ? |
| < | A < B | is A less than B ? |
| <= | A <= B | is A less than or equal to B ? |
| > | A > B | is A Greater than B ? |
| >= | A >= B | is A Greater than or equal to B ? |
| <> | A <> B | is A different than B ? |
These mean what they do in arithmetic. For example:
| relation | result | relation | result | |
|---|---|---|---|---|
| 25 = 25 | true | 25 < 25 | false | |
| 25 <= 25 | true | 25 > 25 | false | |
| 25 >= 25 | true | 25 <> 25 | false | |
Each one of these tests, such as 25 < 25 is called a relational expression. A relational expression tests the relationship between two numbers and says if the relationship is "true" or "false."
| relation | result | relation | result | relation | result | relation | result | |||
|---|---|---|---|---|---|---|---|---|---|---|
| 15 = 25 | false | 15 < 25 | true | 15 = 5 | false | 15 < 5 | false | |||
| 15 <= 25 | true | 15 > 25 | false | 15 <= 5 | false | 15 > 5 | true | |||
| 15 >= 25 | false | 15 <> 25 | true | 15 >= 5 | true | 15 <> 5 | true | |||
Decide on TRUE or FALSE for each of the following:
| comparison | true | false |
|---|---|---|
| 17 = 17 | ||
| 17 < 15 | ||
| 17 <= 15 | ||
| 12 > 12 | ||
| 12 >= 12 | ||
| 12 <> 17 |